package com.singleton.singleton;

/**
 * Singleton 1
 * By checking
 */
/*class A{
	private A(){}
	private static A instance = null;
	
	public static A getA(){
		if(instance == null){
			instance = new A();
		}
		return instance;
	}
	
	public void m1(){
		System.out.println("Hello from Class A");
	}
}*/

/**
 * Singleton 2
 * static-block instantiation
 */
class B{
	private static B instance = null;
	private B(){
		//do-nothing
	}
	static{
		instance = new B();
	}
	public static B getInstance(){
		return instance;
	}
}

/**
 * Singleton 3
 * Eager-Instantiation
 */
/*class C{
	private static C instance = new C();
	private C(){
		// Do-nothing
	}
	public static C getInstance(){
		return instance;
	}
	
	public void m1(){
		System.out.println("Hello from Class C");
	}
}*/



// Test weather singleton or not

public class Test {

	public static void main(String[] args) {
		/*A a1 = A.getA();
		A a2 = A.getA();
		System.out.println(a1==a2);
		a1.m1();
		a2.m1();*/
		
		
		B b1 = B.getInstance();
		B b2 = B.getInstance();
		System.out.println(b1==b2);
		
	
		/*C c1 = C.getInstance();
		C c2 = C.getInstance();
		System.out.println(c1==c2);
		c1.m1();
		c2.m1();*/
		
	}
}

























